using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace PerCiGal.WinForm.Controls
{
    public partial class PCGGradientPanel : Panel
    {
        #region Public Properties

        private int _angle = 90;
        public int Angle
        {
            get
            {
                return _angle;
            }
            set
            {
                _angle = value;
                Invalidate();
            }
        }

        private Color _color1 = Color.Black;
        public Color Color1
        {
            get { return _color1; }
            set
            {
                _color1 = value;
                Invalidate();
            }
        }

        private Color _color2 = Color.DimGray;
        public Color Color2
        {
            get { return _color2; }
            set
            {
                _color2 = value;
                Invalidate(); 
            }
        }

        #endregion

        public PCGGradientPanel()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if ((ClientRectangle.Height != 0) & (ClientRectangle.Width != 0))
            {
                var brush = new LinearGradientBrush(ClientRectangle, _color1, _color2, _angle, true);

                pe.Graphics.FillRectangle(brush, ClientRectangle);

                brush.Dispose();
            }

            // Calling the base class OnPaint
            base.OnPaint(pe);
        }
    }
}
